package com.lhy.gulimall.ware.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lhy.common.utils.PageUtils;
import com.lhy.common.utils.Query;
import com.lhy.gulimall.ware.dao.WareInfoDao;
import com.lhy.gulimall.ware.entity.WareInfoEntity;
import com.lhy.gulimall.ware.service.WareInfoService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("wareInfoService")
public class WareInfoServiceImpl extends ServiceImpl<WareInfoDao, WareInfoEntity> implements WareInfoService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<WareInfoEntity> queryWrapper = new QueryWrapper<>();
        String key = (String) params.get("key");
        if (StringUtils.isNotBlank(key)) {
            queryWrapper.and(w -> {
                w.eq("id", key).or().like("name", key)
                        .or().like("address",key)
                        .or().like("areacode",key);
            });
        }

//        String status = (String) params.get("status");
//        if (StringUtils.isNotBlank(status)) {
//            queryWrapper.eq("sku_id", status);
//        }

        String wareId = (String) params.get("wareId");
        if (StringUtils.isNotBlank(wareId)) {
            queryWrapper.eq("ware_id", wareId);
        }
        IPage<WareInfoEntity> page = this.page(
                new Query<WareInfoEntity>().getPage(params),queryWrapper);

        return new PageUtils(page);
    }

}